<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------

declare(strict_types=1);

namespace app\restaurant\info;

use app\card\model\User;
use app\card\service\UserService;

use app\redbag\info\PermissionRedbag;
use app\restaurant\model\StoreStaff;
use longbingcore\diy\BaseSubscribe;

/**
 * @author shuixian
 * @DataTime: 2019/12/11 16:23
 * Class Subscribe
 * @package app\ucenter\info
 */
class Subscribe extends BaseSubscribe
{
    /**
     * 相应个人中心工具菜单
     *
     * @return mixed
     * @author shuixian
     * @DataTime: 2019/12/12 11:24
     */
   
   public function onAddWorkCenterModelMenu()
   {
   
       $permissson  = new PermissionRestaurant($this->_uniacid);

       $staff_model = new StoreStaff();

       $store       = $staff_model->getStaffStore($this->getUserId(),3);

       if($permissson->pAuth()&&!empty($store)) {


           if($store['role']==1){

               $modelMenu = [
                   "title" => '餐饮门店',
                   "desc" => '',
                   "show" => true,
                   "row" => 4,
                   "list" => [
                       [
                           "title" => "门店数据",
                           "icon" => "icontuijianshangpin",
                           "link" => "/restaurant/pages/staff/store",
                           "linkType" => 4
                       ],
                       [
                           "title" => "订单管理",
                           "icon" => "iconwodedingdan",
                           "link" => "/restaurant/pages/staff/order/list",
                           "linkType" => 4
                       ],
                       [
                           "title" => "售后管理",
                           "icon" => "iconwodeshouhou",
                           "link" => "/restaurant/pages/staff/refund/list",
                           "linkType" => 4
                       ],
                   ]
               ];
           }else{

               $modelMenu = [
                   "title" => '餐饮门店',
                   "desc" => '',
                   "show" => true,
                   "row" => 4,
                   "list" => [
                       [
                           "title" => "订单管理",
                           "icon" => "iconwodedingdan",
                           "link" => "/restaurant/pages/staff/order/list",
                           "linkType" => 4
                       ],
                       [
                           "title" => "售后管理",
                           "icon" => "iconwodeshouhou",
                           "link" => "/restaurant/pages/staff/refund/list",
                           "linkType" => 4
                       ],
                   ]
               ];
           }

   
           return [$modelMenu];
       }
       return [];
   
   }
   


    /**
     * 监听用户中心模块
     *
     * @return array
     * @author shuixian
     * @DataTime: 2019/12/18 14:04
     */
    public function onAddUcenterCompoent(){


        $moduleMenuRestaurantOrder = <<<COMPOENT
		
{
    "title": "餐饮订单",
    "type": "moduleMenuRestaurantOrder",
    "icon": "iconshoporder",
    "isDelete": true,
    "addNumber": 1,
    "attr": [
        {
            "title": "模板名称",
            "type": "Switch",
            "name": "isShowTitle"
        },
        {
            "title": "选择模板",
            "type": "ChooseModule",
            "name": "module",
            "data": [
                {
                    "title": "一行多列",
                    "name": "module-menu-row",
                    "img": "http://lbqny.migugu.com/admin/diy/module-menu-col.jpg"
                },
                {
                    "title": "一行一列",
                    "name": "module-menu-col",
                    "img": "http://lbqny.migugu.com/admin/diy/module-menu-row.jpg"
                }
            ]
        },
        {
            "title": "一行多少列",
            "type": "InputNumber",
            "name": "row"
        }
    ],
    "data": {
        "isShowTitle": false,
        "module": "module-menu-row",
        "row": {
            "number": 4,
            "min": 2,
            "max": 5,
            "label": "请输入"
        },
        "list": [
            {
                "title": "全部",
                "icon": "iconwodedingdan",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/order/list?index=0"
                }
            },
            {
                "title": "待付款",
                "icon": "icondaifukuan1",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/order/list?index=1"
                }
            },
            {
                "title": "待使用",
                "icon": "iconyijiedan",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/order/list?index=2"
                }
            },
            {
                "title": "已完成",
                "icon": "icondingdanyiwancheng",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/order/list?index=3"
                }
            }
            
        ]
    }
}
COMPOENT;

        $moduleMenuRestaurant = <<<COMPOENT
{
    "title": "餐饮工具",
    "type": "moduleMenuRestaurant",
    "icon": "iconshop",
    "isDelete": true,
    "addNumber": 1,
    "attr": [
        {
            "title": "模板名称",
            "type": "Switch",
            "name": "isShowTitle"
        },
        {
            "title": "选择模板",
            "type": "ChooseModule",
            "name": "module",
            "data": [
                {
                    "title": "一行多列",
                    "name": "module-menu-row",
                    "img": "http://lbqny.migugu.com/admin/diy/module-menu-col.jpg"
                },
                {
                    "title": "一行一列",
                    "name": "module-menu-col",
                    "img": "http://lbqny.migugu.com/admin/diy/module-menu-row.jpg"
                }
            ]
        },
        {
            "title": "一行多少列",
            "type": "InputNumber",
            "name": "row"
        }
    ],
    "data": {
        "isShowTitle": false,
        "module": "module-menu-row",
        "row": {
            "number": 4,
            "min": 2,
            "max": 5,
            "label": "请输入"
        },
        "list": [ 
            {
                "title": "我的售后",
                "icon": "iconwodeshouhou",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/refund/list"
                }
            }, 
            {
                "title": "我的卡券",
                "icon": "iconwodekaquan",
                "link": {
                    "type": 2,
                    "url": "/restaurant/pages/coupon/list"
                }
            }, 
            {
                "title": "我的地址",
                "icon": "icondizhi2",
                "link": {
                    "type": 2,
                    "url": "/shop/pages/address/list?is_city=1"
                }
            }
        ]
    }
}
COMPOENT;

        $permission = new PermissionRestaurant($this->_uniacid);
        $compoentList = [] ;
        if($permission->pAuth()){
            $compoentList = [
                json_decode($moduleMenuRestaurantOrder, true),
                json_decode($moduleMenuRestaurant, true)
            ] ;
        }



        return $compoentList ;
    }
 
    /**
     * 监听代理管理端授权小程序事件
     *
     * @param $data
     * @return array
     * @author shuixian
     * @DataTime: 2019/12/27 17:33
     */
    public function onAgentAppAuthEdit($config)
    {


        $permission = new PermissionRestaurant(0);

        if ($permission->sAuth() && $permission->infoConfig['auth_platform']) {

            $auth_switch['formType'] = 'radio';

            $auth_switch['name'] = 'restaurant_switch';

            $auth_switch['value'] = $config ? $config[$auth_switch['name']] : 0;

            $auth_switch['title'] = $permission->info['title'];

            return [$auth_switch];

        }
    }


}